<?php

  session_start();
  include "config.php";
  include "ALcustomer.php";

  if(isset($_SESSION["user"]))
  {
    include "$header";
	include "dobPicker.js";
    include "cardExpiryDate.js";
    include "$body";

?>

<div style="position:absolute; top:0px; left:1px; border:0;">
  <span class="prevPage">Record New Customer Details:Search > </span>
  <span class="page">Record Details</span>
</div>

<?php

    include "$H_rncd";

    if(isset($_SESSION["cs_surname"]))
    {
      $surname = $_SESSION["cs_surname"];
      $given_name = $_SESSION["cs_given_name"];
      $dob_day = $_SESSION["cs_dob_day"];
      $dob_month = $_SESSION["cs_dob_month"];
      $dob_year = $_SESSION["cs_dob_year"];
      $address = $_SESSION["cs_address"];
      $pcode = $_SESSION["cs_pcode"];
      $ph_area1 = $_SESSION["cs_ph_area1"];
      $ph_no1 = $_SESSION["cs_ph_no1"];

      if(isset($_POST["submit"]))
      {
        $title = ltrim($_POST["title"]);
        $ph_area2 = ltrim($_POST["ph_area2"]);
        $ph_no2 = ltrim($_POST["ph_no2"]);
        $card_type1 = ltrim($_POST["card_type1"]);
        $card_name1 = ltrim($_POST["card_name1"]);
        $card_no1_1 = ltrim($_POST["card_no1_1"]);
        $card_no1_2 = ltrim($_POST["card_no1_2"]);
        $card_no1_3 = ltrim($_POST["card_no1_3"]);
        $card_no1_4 = ltrim($_POST["card_no1_4"]);
        $card_expiry_month1 = ltrim($_POST["card_expiry_month1"]);
        $card_expiry_year1 = ltrim($_POST["card_expiry_year1"]);
        $card_type2 = ltrim($_POST["card_type2"]);
        $card_name2 = ltrim($_POST["card_name2"]);
        $card_no2_1 = ltrim($_POST["card_no2_1"]);
        $card_no2_2 = ltrim($_POST["card_no2_2"]);
        $card_no2_3 = ltrim($_POST["card_no2_3"]);
        $card_no2_4 = ltrim($_POST["card_no2_4"]);
        $card_expiry_month2 = ltrim($_POST["card_expiry_month2"]);
        $card_expiry_year2 = ltrim($_POST["card_expiry_year2"]);

        if(validRecordDetails($title, $surname, $given_name, $dob_day, $dob_month, $dob_year, $address, $pcode, $ph_area1, $ph_no1, $ph_area2, $ph_no2, $card_type1, $card_name1, $card_no1_1, $card_no1_2, $card_no1_3, $card_no1_4, $card_expiry_month1, $card_expiry_year1, $card_type2, $card_name2, $card_no2_1, $card_no2_2, $card_no2_3, $card_no2_4, $card_expiry_month2, $card_expiry_year2, "new"))
        {
          $_SESSION["cr_title"] = $title;
          $_SESSION["cr_surname"] = $surname;
          $_SESSION["cr_given_name"] = $given_name;
          $_SESSION["cr_dob_day"] = $dob_day;
          $_SESSION["cr_dob_month"] = $dob_month;
          $_SESSION["cr_dob_year"] = $dob_year;
          $_SESSION["cr_address"] = $address;
          $_SESSION["cr_pcode"] = $pcode;
          $_SESSION["cr_ph_area1"] = $ph_area1;
          $_SESSION["cr_ph_no1"] = $ph_no1;
          $_SESSION["cr_ph_area2"] = $ph_area2;
          $_SESSION["cr_ph_no2"] = $ph_no2;
          $_SESSION["cr_card_type1"] = $card_type1;
          $_SESSION["cr_card_name1"] = $card_name1;
          $_SESSION["cr_card_no1_1"] = $card_no1_1;
          $_SESSION["cr_card_no1_2"] = $card_no1_2;
          $_SESSION["cr_card_no1_3"] = $card_no1_3;
          $_SESSION["cr_card_no1_4"] = $card_no1_4;
          $_SESSION["cr_card_expiry_month1"] = $card_expiry_month1;
          $_SESSION["cr_card_expiry_year1"] = $card_expiry_year1;

          if($card_type2 == "Select:" || empty($card_name2) || $card_name2 == "" || empty($card_no2_1) || $card_no2_1 == "" ||  empty($card_no2_2) || $card_no2_2 == "" || empty($card_no2_3) || $card_no2_3 == "" || empty($card_no2_4) || $card_no2_4 == "")
          {
            $_SESSION["cr_card_type2"] = "";
            $_SESSION["cr_card_name2"] = "";
            $_SESSION["cr_card_no2_1"] = "";
            $_SESSION["cr_card_no2_2"] = "";
            $_SESSION["cr_card_no2_3"] = "";
            $_SESSION["cr_card_no2_4"] = "";
            $_SESSION["cr_card_expiry_month2"] = "";
            $_SESSION["cr_card_expiry_year2"] = "";
          }
          else
          {
            $_SESSION["cr_card_type2"] = $card_type2;
            $_SESSION["cr_card_name2"] = $card_name2;
            $_SESSION["cr_card_no2_1"] = $card_no2_1;
            $_SESSION["cr_card_no2_2"] = $card_no2_2;
            $_SESSION["cr_card_no2_3"] = $card_no2_3;
            $_SESSION["cr_card_no2_4"] = $card_no2_4;
            $_SESSION["cr_card_expiry_month2"] = $card_expiry_month2;
            $_SESSION["cr_card_expiry_year2"] = $card_expiry_year2;
          }

          echo "<SCRIPT language='Javascript'>";
          echo "  window.location.href = 'recordNewCustomerDetails_2confirmDetails.php';";
          echo "</SCRIPT>";
        }
        else
        {
          showForm($dob_month, $dob_day, $dob_year);
          echo "<SCRIPT language='Javascript'>";
          echo "  customerForm.title.selectedIndex='".($title + 1)."';";
          echo "  customerForm.surname.value='".$surname."';";
          echo "  customerForm.given_name.value='".$given_name."';";
          echo "  customerForm.months.selectedIndex=0;";
          echo "  customerForm.days.selectedIndex=0;";
          echo "  customerForm.years.selectedIndex=0;";
          echo "  customerForm.address.value='".$address."';";
          echo "  customerForm.pcode.value='".$pcode."';";
          echo "  customerForm.ph_area1.value='".$ph_area1."';";
          echo "  customerForm.ph_no1.value='".$ph_no1."';";
          echo "  customerForm.ph_area2.value='".$ph_area2."';";
          echo "  customerForm.ph_no2.value='".$ph_no2."';";
          echo "  customerForm.card_type1.selectedIndex='".($card_type1 + 1)."';";
          echo "  customerForm.card_name1.value='".$card_name1."';";
          echo "  customerForm.card_no1_1.value='".$card_no1_1."';";
          echo "  customerForm.card_no1_2.value='".$card_no1_2."';";
          echo "  customerForm.card_no1_3.value='".$card_no1_3."';";
          echo "  customerForm.card_no1_4.value='".$card_no1_4."';";
          echo "  customerForm.card_expiry_month1.selectedIndex='".($card_expiry_month1 - 1)."';";
          echo "  customerForm.card_expiry_year1.selectedIndex='".($card_expiry_year1 - 2007)."';";
          echo "  customerForm.card_type2.selectedIndex='".($card_type2 + 1)."';";
          echo "  customerForm.card_name2.value='".$card_name2."';";
          echo "  customerForm.card_no2_1.value='".$card_no2_1."';";
          echo "  customerForm.card_no2_2.value='".$card_no2_2."';";
          echo "  customerForm.card_no2_3.value='".$card_no2_3."';";
          echo "  customerForm.card_no2_4.value='".$card_no2_4."';";
          echo "  customerForm.card_expiry_month2.selectedIndex='".($card_expiry_month2 - 1)."';";
          echo "  customerForm.card_expiry_year2.selectedIndex='".($card_expiry_year2 - 2007)."';";
          echo "</SCRIPT>";
        }
      }
	  else
      {
        showForm($dob_month, $dob_day, $dob_year);
        if(isset($_SESSION["cr_title"]))
        {
          $title = ltrim($_SESSION["cr_title"]);
          $ph_area2 = ltrim($_SESSION["cr_ph_area2"]);
          $ph_no2 = ltrim($_SESSION["cr_ph_no2"]);
          $card_type1 = ltrim($_SESSION["cr_card_type1"]);
          $card_name1 = ltrim($_SESSION["cr_card_name1"]);
          $card_no1_1 = ltrim($_SESSION["cr_card_no1_1"]);
          $card_no1_2 = ltrim($_SESSION["cr_card_no1_2"]);
          $card_no1_3 = ltrim($_SESSION["cr_card_no1_3"]);
          $card_no1_4 = ltrim($_SESSION["cr_card_no1_4"]);
          $card_expiry_month1 = ltrim($_SESSION["cr_card_expiry_month1"]);
          $card_expiry_year1 = ltrim($_SESSION["cr_card_expiry_year1"]);
          $card_type2 = ltrim($_SESSION["cr_card_type2"]);
          $card_name2 = ltrim($_SESSION["cr_card_name2"]);
          $card_no2_1 = ltrim($_SESSION["cr_card_no2_1"]);
          $card_no2_2 = ltrim($_SESSION["cr_card_no2_2"]);
          $card_no2_3 = ltrim($_SESSION["cr_card_no2_3"]);
          $card_no2_4 = ltrim($_SESSION["cr_card_no2_4"]);
          $card_expiry_month2 = ltrim($_SESSION["cr_card_expiry_month2"]);
          $card_expiry_year2 = ltrim($_SESSION["cr_card_expiry_year2"]);
          
          echo "<SCRIPT language='Javascript'>";
          echo "  customerForm.title.selectedIndex='".($title + 1)."';";
          echo "  customerForm.ph_area2.value='".$ph_area2."';";
          echo "  customerForm.ph_no2.value='".$ph_no2."';";
          echo "  customerForm.card_type1.selectedIndex='".($card_type1 + 1)."';";
          echo "  customerForm.card_name1.value='".$card_name1."';";
          echo "  customerForm.card_no1_1.value='".$card_no1_1."';";
          echo "  customerForm.card_no1_2.value='".$card_no1_2."';";
          echo "  customerForm.card_no1_3.value='".$card_no1_3."';";
          echo "  customerForm.card_no1_4.value='".$card_no1_4."';";
          echo "  customerForm.card_expiry_month1.selectedIndex='".($card_expiry_month1 - 1)."';";
          echo "  customerForm.card_expiry_year1.selectedIndex='".($card_expiry_year1 - 2007)."';";
          echo "  customerForm.card_type2.selectedIndex='".($card_type2 + 1)."';";
          echo "  customerForm.card_name2.value='".$card_name2."';";
          echo "  customerForm.card_no2_1.value='".$card_no2_1."';";
          echo "  customerForm.card_no2_2.value='".$card_no2_2."';";
          echo "  customerForm.card_no2_3.value='".$card_no2_3."';";
          echo "  customerForm.card_no2_4.value='".$card_no2_4."';";
          echo "  customerForm.card_expiry_month2.selectedIndex='".($card_expiry_month2 - 1)."';";
          echo "  customerForm.card_expiry_year2.selectedIndex='".($card_expiry_year2 - 2007)."';";
          echo "</SCRIPT>";
        }
        echo "<SCRIPT language='Javascript'>";
        echo "  customerForm.surname.value='".$surname."';";
        echo "  customerForm.given_name.value='".$given_name."';";
        echo "  customerForm.months.selectedIndex=0;";
        echo "  customerForm.days.selectedIndex=0;";
        echo "  customerForm.years.selectedIndex=0;";
        echo "  customerForm.address.value='".$address."';";
        echo "  customerForm.pcode.value='".$pcode."';";
        echo "  customerForm.ph_area1.value='".$ph_area1."';";
        echo "  customerForm.ph_no1.value='".$ph_no1."';";
        echo "</SCRIPT>";
      }
    }
    else
    {
      echo "<SCRIPT language='Javascript'>";
      echo "  window.location.href = 'recordNewCustomerDetails.php';";
      echo "</SCRIPT>";
    }
    include "$footer";
  }
  else
  {
    session_destroy();
    echo "<SCRIPT language='Javascript'>";
    echo "  parent.window.location.href = 'index.php';";
    echo "</SCRIPT>";
  }

  function showForm($dob_month, $dob_day, $dob_year)
  {

?>
<font color="red">*</font> = mandatory field
<p>
<FORM name="customerForm" action="" method="post">
<TABLE class="customer" cellpadding="5" cellspacing="5">
  <TR>
    <TD class="cField">
      Title<font color="red">*</font>
    </TD>
    <TD class="cDetails">
	  <select class="cTitle" name="title" style="width:70px;">
        <option value="Select:">Select:</option>
        <option value="0">Miss</option>
        <option value="1">Mr</option>
        <option value="2">Mrs</option>
        <option value="3">Ms</option>
      </select>
    </TD>
  </TR>
  <TR>
    <TD class="cField">
	  Surname<font color="red">*</font>
	</TD>
    <TD class="cDetails">
	  <input type="text" class="customer" name="surname" style="width:150px;" readonly/>
	</TD>
  </TR>
  <TR>
    <TD class="cField">
	  Given Name<font color="red">*</font>
	</TD>
	<TD class="cDetails">
	  <input type="text" class="customer" name="given_name" style="width:150px" readonly/>
	</TD>
  </TR>
  <TR>
    <TD class="cField">
      Date of Birth<font color="red">*</font>
    </TD>
    <TD class="cDetails">
      <select class="cMonth" name="months">
        <option value="<?php echo $dob_month; ?>"><?php echo findMonth($dob_month); ?></option>
      </select>
      &nbsp;
      <select class="cDay" name="days">
        <option value="<?php echo $dob_day; ?>"><?php echo $dob_day; ?></option>
      </select>
      &nbsp;
      <select class="cYear" name="years">
        <option value="<?php echo $dob_year; ?>"><?php echo $dob_year; ?></option>
      </select>
    </TD>
  </TR>
  <TR>
    <TD class="cField">
      Address<font color="red">*</font>
    </TD>
    <TD class="cDetails">
      <input type="text" class="customer" name="address" style="width:200px;" value="<?php echo $address; ?>" readonly/>
    </TD>
  </TR>
  <TR>
    <TD class="cField">
      Post Code<font color="red">*</font>
    </TD>
    <TD class="cDetails">
      <input type="text" class="customer" name="pcode" style="width:50px;" value="<?php echo $pcode; ?>" readonly/>
    </TD>
  </TR>
  <TR>
    <TD class="cField">
      Phone (H)/(M)<font color="red">*</font>
      <br /><b>(W)</b>
    </TD>
    <TD class="cDetails">
      ( <input type="text" class="customer" name="ph_area1" style="width:30px;" readonly/> ) <input type="text" class="customer" name="ph_no1" style="width:100px;" readonly/>
      <br />
      ( <input type="text" class="customer" name="ph_area2" style="width:30px;" /> ) <input type="text" class="customer" name="ph_no2" style="width:100px;" />
    </TD>
  </TR>
  <TR>
    <TD class="cField" valign="top">
      Preferred Credit Card<font color="red">*</font>
    </TD>
    <TD class="cDetails">
      <TABLE style="border:1px solid #000000">
        <TR>
          <TD>
            <TR>
              <TD>
                Card Type: &nbsp; 
                <select name="card_type1" style="width:100px">
                  <option value="Select:">Select:</option>
                  <option value="0">Mastercard</option>
                  <option value="1">Visa</option>
                  <option value="2">Amex</option>
                  <option value="3">Diners Club</option>
                </select>
              </TD>
            </TR>
          </TD>
        </TR>
        <TR>
          <TD>
            Card Name: &nbsp; 
            <input type="text" class="rcdCardName" name="card_name1" style="width:150px">
          </TD>
        </TR>
        <TR>
          <TD>
            Card Number: &nbsp; 
            <input type="text" class="rcdCardNumber" name="card_no1_1" style="width:40px;">
            <input type="text" class="rcdCardNumber" name="card_no1_2" style="width:40px;">
            <input type="text" class="rcdCardNumber" name="card_no1_3" style="width:40px;">
            <input type="text" class="rcdCardNumber" name="card_no1_4" style="width:40px;">
          </TD>
        </TR>
        <TR>
          <TD>
            Expiry Date: &nbsp; 
            <SCRIPT>
              fill_select_ex(document.customerForm, "card_expiry_month1");
              year_install_ex(document.customerForm, "card_expiry_year1");
            </script>
          </TD>
        </TR>
      </TABLE>
    </TD>
  </TR>
  <TR>
    <TD class="cField" valign="top">
      Alternate Credit Card
    </TD>
    <TD class="cDetails">
      <TABLE style="border:1px solid #000000">
        <TR>
          <TD>
            <TR>
              <TD>
                Card Type: &nbsp; 
                <select name="card_type2" style="width:100px">
                  <option value="Select:">Select:</option>
                  <option value="0">Mastercard</option>
                  <option value="1">Visa</option>
                  <option value="2">Amex</option>
                  <option value="3">Diners Club</option>
                </select>
              </TD>
            </TR>
          </TD>
        </TR>
        <TR>
          <TD>
            Card Name: &nbsp; 
            <input type="text" class="rcdCardName" name="card_name2" style="width:150px">
          </TD>
        </TR>
        <TR>
          <TD>
            Card Number: &nbsp; 
            <input type="text" class="rcdCardNumber" name="card_no2_1" style="width:40px;">
            <input type="text" class="rcdCardNumber" name="card_no2_2" style="width:40px;">
            <input type="text" class="rcdCardNumber" name="card_no2_3" style="width:40px;">
            <input type="text" class="rcdCardNumber" name="card_no2_4" style="width:40px;">
          </TD>
        </TR>
        <TR>
          <TD>
            Expiry Date: &nbsp; 
            <SCRIPT>
              fill_select_ex(document.customerForm, "card_expiry_month2");
              year_install_ex(document.customerForm, "card_expiry_year2");
            </script>
          </TD>
        </TR>
      </TABLE>
    </TD>
  </TR>
</TABLE>
<p>
<input class="submit_off" type="submit" value="Submit" name="submit" onmouseover="className='submit_on'" onmouseout="className='submit_off'" />
</FORM>
</BODY>

<?php

 }

 function findMonth($month)
 {
   switch ($month)
   {
     case "01": return "January";
     case "02": return "February";
     case "03": return "March";
     case "04": return "April";
     case "05": return "May";
     case "06": return "June";
     case "07": return "July";
     case "08": return "August";
     case "09": return "September";
     case "10": return "October";
     case "11": return "November";
     case "12": return "December";
   }
 }

?>